package com.taijihuabao.common.jsonresult;

import java.io.Serializable;

/**
 * @author Admin
 */
public class JsonResult implements Serializable {

    private String resultCode;

    private String resultMessage;

    private Object content;

    private boolean success = false;

    public JsonResult() {
    }

    public JsonResult(String resultCode, String resultMessage) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
    }
    private void setResultCode(ResponseCode code) {
        this.resultCode = code.getCode();
        this.resultMessage = code.getValue();
    }
    private void setContent(Object content) {
        this.content = content;
    }
    private void setSuccess(boolean success){
        this.success = success;
    }
    /**
     * 操作失败，自定义code和msg
     */
    public  static JsonResult failure(String resultCode, String resultMessage) {
        JsonResult result = new JsonResult(resultCode,resultMessage);
        return result;
    }

    /**
     * 操作成功，没有返回的数据
     */
    public static JsonResult success() {
        JsonResult result = new JsonResult();
        result.setResultCode(ApplicationResponseCode.SUCCEEDED);
        result.setSuccess(true);
        return result;
    }

    /**
     * 操作成功，有返回的数据
     */
    public static JsonResult success(Object data) {
        JsonResult result = new JsonResult();
        result.setResultCode(ApplicationResponseCode.SUCCEEDED);
        result.setContent(data);
        result.setSuccess(true);
        return result;
    }

    /**
     * 操作失败，没有返回的数据
     */
    public static JsonResult failure(ApplicationResponseCode resultCode) {
        JsonResult result = new JsonResult();
        result.setResultCode(resultCode);
        result.setSuccess(false);
        return result;
    }

    /**
     * 操作失败，有返回的数据
     */
    public static JsonResult failure(ApplicationResponseCode resultCode, Object data) {
        JsonResult result = new JsonResult();
        result.setResultCode(resultCode);
        result.setContent(data);
        result.setSuccess(false);
        return result;
    }

    public String getResultCode() {
        return resultCode;
    }

    public void setResultCode(String resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMessage() {
        return resultMessage;
    }

    public void setResultMessage(String resultMessage) {
        this.resultMessage = resultMessage;
    }

    public Object getContent() {
        return content;
    }

    public boolean isSuccess() {
        return success;
    }
}
